package com.rocsea.robot.service;

import com.rocsea.robot.config.build.KettleBuildConfig;
import com.rocsea.robot.model.bo.*;
import com.rocsea.robot.model.entity.*;
import com.rocsea.robot.utils.KettleBuildUtils;

import java.util.List;
import java.util.Objects;

/**
 * @Author RocSea
 * @Date 2023/1/17
 */
public class KettleBuildProxy {
    private TransformationService transformationService;

    private JobService jobService;

    private DirectoryService directoryService;

    private DatabaseService databaseService;

    private KettleBuildConfig kettleBuildConfig;

    public KettleBuildProxy(TransformationService transformationService,
                            JobService jobService,
                            DirectoryService directoryService,
                            DatabaseService databaseService,
                            KettleBuildConfig kettleBuildConfig) {
        this.transformationService = transformationService;
        this.jobService = jobService;
        this.directoryService = directoryService;
        this.databaseService = databaseService;
        this.kettleBuildConfig = kettleBuildConfig;
    }

    public DirectoryPoint getDirectoryPoint() {
        return directoryService.getPoints();
    }

    public DatabasePoint getDatabasePoint() {
        return databaseService.getPoints();
    }

    public TransformationPoint getTransformationPoint(Long templateId) {
        List<TransformationDO> transformationTemplateList = transformationService.listTransformation(templateId);
        IdMaxTransRelated idMaxTransRelated = KettleBuildUtils.getIdMaxTransRelated();
        if (Objects.isNull(idMaxTransRelated)) {
            idMaxTransRelated = transformationService.getIdMaxTransRelated();
            KettleBuildUtils.setIdMaxTransRelated(idMaxTransRelated);
        }
        return new TransformationPoint(transformationTemplateList);
    }

    public JobPoint getJobPoint(Long templateId) {
        IdMaxJobRelated idMaxJobRelated = jobService.getidMaxJobRelated();
        List<JobDO> jobDOS = jobService.listJob(templateId);
        return new JobPoint(jobDOS, idMaxJobRelated);
    }

    public List<TransAttributeDO> listTransAttribute(Long idTransformation) {
        return transformationService.listTransAttribute(idTransformation);
    }

    public List<StepDO> listStep(Long templateIdTransformation) {
        return transformationService.listStep(templateIdTransformation);
    }

    public List<StepAttributeDO> listStepAttribute(Long idStep) {
        return transformationService.listStepAttribute(idStep);
    }

    public List<StepDatabaseDO> listStepDatabase(Long templateIdTransformation) {
        return transformationService.listStepDatabase(templateIdTransformation);
    }

    public List<TransHopDO> listTransHop(Long templateIdTransformation) {
        return transformationService.listTransHop(templateIdTransformation);
    }

    public List<TransStepConditionDO> listTransStepCondition(Long templateIdTransformation) {
        return transformationService.listTransStepCondition(templateIdTransformation);
    }

    public List<ConditionDO> listCondition(List<Long> idConditions) {
        return transformationService.listCondition(idConditions);
    }

    public List<JobAttributeDO> listJobAttribute(Long templateIdJob) {
        return jobService.listJobAttribute(templateIdJob);
    }

    public List<JobentryDO> listJobEntry(Long idJob) {
        return jobService.listJobEntry(idJob);
    }

    public List<JobentryCopyDO> queryJobEntryCopy(Long idJob) {
        return jobService.queryJobEntryCopy(idJob);
    }

    public List<JobentryAttributeDO> listJobEntryAttribute(Long idJobentry) {
        return jobService.listJobEntryAttribute(idJobentry);
    }

    public List<JobentryCopyDO> listJobEntryCopy(Long idJobentry) {
        return jobService.listJobEntryCopy(idJobentry);
    }

    public List<JobentryDatabaseDO> listJobEntryDatabase(Long idJobentry) {
        return jobService.listJobEntryDatabase(idJobentry);
    }

    public List<JobHopDO> listJobHop(Long idJob) {
        return jobService.listJobHop(idJob);
    }

    public List<JobNoteDO> listJobNote(Long idJob) {
        return jobService.listJobNote(idJob);
    }

    public Long getIdConnectionIfNull() {
        return databaseService.getIdConnectionIfNull();
    }

    public KettleBuildConfig getKettleBuildConfig() {
        return kettleBuildConfig;
    }
}
